class Solution {
public:
    vector<vector<int>> levelOrder(TreeNode* root) {
        vector<vector<int>> res;
        queue<TreeNode*> s;
        if (root != NULL) 
            s.push(root);
        while(!s.empty()){
            vector<int> v;
            int size=s.size();
            for(int i=0;i<size;i++){
                TreeNode* t=s.front();
                s.pop();
                v.push_back(t->val);
                if(t->left){
                    s.push(t->left);
                }
                if(t->right){
                    s.push(t->right);
                }
            }
            res.push_back(v);
        }
        return res;
    }
};
